package com.tag.pub;

import com.erp.erp_entitys.Role.RoleEntity;
import com.erp.erp_entitys.User.UserEntity;
import com.erp.erp_servers.User.imp.ImpUserSerice;
import com.erp.quertz.SpringUtil;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.List;

public class PrivilegeTag  extends TagSupport{

    private static final long serialVersionUID = -532517444654109642L;
    private String operateID;
    private String roleID;
    private String mark;
    public void setMark(String mark) {
        this.mark = mark;
    }
    public void setRoleID(String roleID) {
        this.roleID = roleID;
    }
    public void setOperateID(String operateID) {
        this.operateID = operateID;
    }
    public int doStartTag() throws JspException {
        HttpSession session = pageContext.getSession();
        UserEntity user = (UserEntity)session.getAttribute("user");
        //String roles = user.getRoles();
        ImpUserSerice userSerice = SpringUtil.getBean(ImpUserSerice.class);
        List<RoleEntity> allRoleByUserCode = userSerice.getAllRoleByUserCode(user);

        boolean tf=false;
        for(RoleEntity re:allRoleByUserCode){
            if(re==null){
                continue;
            }
            if(re.getCode().equals(roleID)){
                tf=true;
                break;
            }
        }
        if(tf){
            return EVAL_PAGE;
        }else{
            return SKIP_BODY;
        }
       /* if( roles.contains(roleID)){
            return EVAL_PAGE;
        }
        else{
            return SKIP_BODY;
        }*/
    }

}